package com.ruoyi.teacher.teacherUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class TimeUtil {

    /**
     * 获取本月月初、月末时间戳
     * @return
     */
    public static List<Long> getTimeStamp() throws ParseException {
        List<Long> list = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        Date today = new Date();
        String strDateFormat = "yyyy-MM";
        SimpleDateFormat f = new SimpleDateFormat(strDateFormat);
        String format = f.format(today);
        // 本月一号
        String startTime = format + "-26";
        calendar.setTime(today);
        int actualMaximum = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        String endTime = format + "-" + actualMaximum;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Long startTimeStamp = simpleDateFormat.parse(startTime).getTime();
        Long endTimeStamp = simpleDateFormat.parse(endTime).getTime();
        list.add(startTimeStamp);
        list.add(endTimeStamp);
        return list;
    }
}
